package com.itxx.homework;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

/*请编写斗地主洗牌发牌程序*/
public class Test3 {
    public static void main(String[] args) {
        HashMap<Integer, String> poker = new HashMap<>();
        ArrayList<Integer> pokerNumber = new ArrayList<>();
        //准备花色
        String[] color = {"♥", "♠", "♣", "♦"};
        //准备牌号
        String[] number = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
        //大小王
        poker.put(0, "大王");
        poker.put(1, "小王");
        pokerNumber.add(0);
        pokerNumber.add(1);
        //其余牌
        int index = 2;
        for (String c : color) {
            for (String n : number) {
                poker.put(index, c + n);
                pokerNumber.add(index);
                index++;
            }
        }

        System.out.println(poker);

        //打乱
        Collections.shuffle(pokerNumber);
        System.out.println(pokerNumber);

        //发牌
        ArrayList<Integer> player1 = new ArrayList<>();
        ArrayList<Integer> player2 = new ArrayList<>();
        ArrayList<Integer> player3 = new ArrayList<>();
        ArrayList<Integer> hands = new ArrayList<>();
        for (int i = 0; i < pokerNumber.size(); i++) {
            if(i < 3){
                hands.add(pokerNumber.get(i));
            }else if(i%3 == 0){
                player1.add(pokerNumber.get(i));
            }else if(i%3 == 1){
                player2.add(pokerNumber.get(i));
            }else if(i%3 == 2){
                player3.add(pokerNumber.get(i));
            }
        }
        // 排序

      /*  Collections.sort(player1);
        Collections.sort(player2);
        Collections.sort(player3);
        Collections.sort(hands);
*/
        //看牌
        lookPoker("农民1",player1,poker);
        lookPoker("农民2",player2,poker);
        lookPoker("地主",player3,poker);
        lookPoker("底牌",hands,poker);


    }



    private static void lookPoker(String name, ArrayList<Integer> player, HashMap<Integer, String> poker) {
        System.out.println(name+ ":" + " ");
        for (Integer num : player) {
            System.out.print(poker.get(num)+ " ");
        }
        System.out.println();
    }
}
